<style>
  .picImg {
    width: 40px;
    height: 40px;
  }
</style>
<template>
  <div class="app-container">
    <!--&lt;!&ndash; 查询和其他操作 &ndash;&gt;-->
    <div class="filter-container">
      <el-date-picker
        v-model="infoTime.startTime"
        type="datetime"
        placeholder="查询开始日期"
        value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
      -
      <el-date-picker
        v-model="infoTime.endTime"
        type="datetime"
        placeholder="查询结束日期"
        value-format="yyyy-MM-dd HH:mm:ss">
      </el-date-picker>
      <!--状态暂无添加-->
      <el-select v-model="dotext.status" placeholder="请选择状态">
        <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      <el-button @click="getList" type="primary">查询</el-button>
      <el-button class="filter-item" type="primary" icon="el-icon-edit"
                 @click="handleEdit">上传
      </el-button>
    </div>
    <!-- 查询结果 -->
    <el-table v-loading="listLoading" :data="list" element-loading-text="正在查询中。。。" border fit highlight-current-row
              @row-click="detail">

      <el-table-column align="center" min-width="100" label="表单ID" prop="id"/>
      <el-table-column align="center" min-width="100" label="表单编号" prop="formNo"/>
      <el-table-column align="center" min-width="100" label="上传时间" prop="addTime"/>
      <el-table-column align="center" min-width="100" label="保险公司ID" prop="insuranceID"/>
      <el-table-column align="center" min-width="100" label="权益服务商ID" prop="insurserviceID"/>
      <el-table-column align="center" min-width="100" label="保理公司ID" prop="factoringID"/>
      <el-table-column align="center" min-width="100" label="保单总数" prop="billCount"/>
      <el-table-column align="center" min-width="100" label="服务费总额" prop="amount"/>
      <el-table-column align="center" min-width="100" label="表单状态" prop="status"/>
      <el-table-column align="center" min-width="100" label="权益服务商处理时间" prop="advanceTime"/>
      <el-table-column align="center" min-width="100" label="需要垫资保单数" prop="advanceCount"/>
      <el-table-column align="center" min-width="100" label="需要垫资金额" prop="advanceAmount"/>
      <el-table-column align="center" min-width="100" label="垫资支付时间" prop="advanceTime"/>
      <el-table-column align="center" min-width="100" label="回款总额" prop="repayAmount"/>
      <el-table-column align="center" min-width="100" label="回款时间" prop="repayTime"/>
      <el-table-column align="center" min-width="100" label="上传备注" prop="remarkUp"/>
      <el-table-column align="center" min-width="100" label="垫资申请备注" prop="remarkAdv"/>
      <el-table-column align="center" label="操作" width="250" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="danger" size="mini"
                     @click="doDelete(scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.pageSize"
                @pagination="getList"/>
    <!--详情表单列表-->
    <el-dialog :visible.sync="editDialogVisible" title="textMap[dialogStatus]">
      <el-table v-loading="listLoading1" :data="list1" element-loading-text="正在查询中。。。" border fit highlight-current-row>

        <el-table-column align="center" min-width="100" label="表单ID" prop="id"/>
        <el-table-column align="center" min-width="100" label="保单号或合同号" prop="billNo"/>
        <el-table-column align="center" min-width="100" label="保单金额" prop="billAmount"/>
        <el-table-column align="center" min-width="100" label="代理手续费" prop="fee"/>
        <el-table-column align="center" min-width="100" label="代理人身份证号" prop="agentID"/>
        <el-table-column align="center" min-width="100" label="代理人编码" prop="agentNo"/>
        <el-table-column align="center" min-width="100" label="是否需要垫资" prop="isAdvance"/>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="editDialogVisible = false">确定</el-button>
      </div>
    </el-dialog>
    <!--上传表单列表-->
    <el-dialog :visible.sync="editDialogVisible1" :title="textMap[dialogStatus]">
      <el-form ref="editForm" :rules="editFormRules" :model="editForm" status-icon label-position="left"
               label-width="100px" style="width: 400px; margin-left:50px;">
        <el-form-item label="表单编号" prop="formNo">
          <el-input v-model="editForm.formNo" auto-complete="off"/>
        </el-form-item>
        <el-form-item label="备注" prop="insuragentID">
          <el-input v-model="editForm.insuragentID" auto-complete="off"/>
        </el-form-item>
        <el-form-item label="保代公司ID" prop="factoringID">
          <el-input v-model="editForm.factoringID" auto-complete="off"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="editForm.remark" auto-complete="off"/>
        </el-form-item>
        <el-form-item label="明细列表" prop="billFile">
          <el-input v-model="editForm.billFile" auto-complete="off"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible1 = false">取消</el-button>
        <el-button type="primary" @click="doCreate">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {doGet, doPost} from '@/api'
  import {cities} from '@/utils/base'
  import Pagination from '@/components/Pagination' // Secondary package based on el-pagination

  const FETCH_PAGE = 'bxagentfee.html'
  const FETCH_URL = {
    LIST: `${FETCH_PAGE}?op=list`,
    CREATE: `${FETCH_PAGE}?op=billlist`,
    EDIT: `${FETCH_PAGE}?op=formup`,
    DELETE: `${FETCH_PAGE}?op=formreup`,
    IMPORT: `${FETCH_PAGE}?op=formdel`,
    FORMREPAY: `${FETCH_PAGE}?op=formrepay`
  }
  export default {
    name: 'bxservicefee',
    components: {Pagination},
    filters: {},
    data() {
      return {
//        时间
        value: '',
        infoTime:{
          startTime:undefined,
          endTime:undefined,
        },
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }, {
            text: '昨天',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit('pick', date);
            }
          }, {
            text: '一周前',
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', date);
            }
          }]},
//        状态
        options: [{
          value: '',
          label: '全部'
        }, {
          value: '已上传',
          label: '已上传'
        }, {
          value: '未上传',
          label: '未上传'
        }],
//        列表加等待效果
        list: [],
        list1: [],
        total: 0,
        listLoading: true,
        listLoading1: true,
//        分页   --暂时无用
        listQuery: {
          page: 1,
          pageSize: 20
        },
//        弹窗标题
        textMap: {
          datail: '表单明细列表',
          create: '上传表单列表'
        },
//        查询参数
        dotext: {
          startTime: undefined,
          endTime: undefined,
          status: undefined,
        },
//        上传参数
        editForm: {
          formNo: undefined,
          insuragentID: undefined,
          factoringID: undefined,
          remark: undefined,
          billFile: undefined,
        },
//        上传参数表单验证
        editFormRules: {
          formNo: [{required: true, message: '表单编号不允许为空', trigger: 'blur'}],
          insuragentID: [{required: true, message: '保代公司ID不允许为空', trigger: 'blur'}],
          factoringID: [{required: true, message: '保理公司ID不允许为空', trigger: 'blur'}],
          billFile: [{required: true, message: '明细列表不允许为空', trigger: 'blur'}]
        },
//        弹窗出没
        editDialogVisible: false,
        editDialogVisible1: false,
      }
    },
//    直接获取列表
    created() {
      this.getList()
    },
    methods: {
//      获取列表函数
      getList() {
        this.listLoading = true
        doGet(FETCH_URL.LIST, this.infoTime).then(response => {
          this.list = response.rows
          this.total = response.rows.length
          this.listLoading = false
        }).catch(() => {
          this.list = []
          this.total = 0
          this.listLoading = false
        })
      },
//      详情列表
      detail(row) {
        this.dialogStatus = 'datail'
        this.editDialogVisible = true
        this.listLoading1 = true
//        console.log(row.id)
        doGet(FETCH_URL.CREATE, {id: row.id}).then(response => {
          console.log(response);
          this.list1 = response.rows
          this.listLoading1 = false
        }).catch(() => {
          this.list = [];
          this.total = 0;
          this.listLoading = false
        })
      },
//      删除按钮
      doDelete(row) {
        doGet(FETCH_URL.IMPORT, {id: row.id})
          .then(response => {
            this.$notify.success({
              title: '成功',
              message: '删除成功'
            })
            const index = this.list.indexOf(row)
            this.list.splice(index, 1)
            this.total--
          })
          .catch(response => {
            this.$notify.error({
              title: '失败',
              message: response.message
            })
          })
      },
//      上传参数的重置
      handleEdit(row) {
        this.dialogStatus = 'create'
        this.editDialogVisible1 = true
        this.$nextTick(() => {
          this.$refs['editForm'].clearValidate()
        })
      },
//      上传参数
      doCreate() {
        this.$refs['editForm'].validate(valid => {
          if (valid) {
            let sendData = {
              ...this.editForm,
            }
            doGet(FETCH_URL.EDIT, sendData)
              .then(response => {
                this.getList()
                this.editDialogVisible = false
                this.$notify.success({
                  title: '成功',
                  message: '上传成功'
                })
              })
              .catch(response => {
                this.$notify.error({
                  title: '失败',
                  message: response.message
                })
              })
          }
        })
      },
    }
  }
</script>
